﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UtilZ.Dotnet.DBIBase;

namespace UtilZ.Dotnet.DBSQLite
{
    internal partial class SQLiteDBAccess : DBAccessAbs
    {
        /// <summary>
        /// sql语句最大长度
        /// The maximum number of bytes in the text of an SQL statement is limited to SQLITE_MAX_SQL_LENGTH which defaults to 1000000. You can red
        /// </summary>
        private const long SQL_MAX_LENGTH = 1000000;
        public SQLiteDBAccess(IDBInteraction dbInteraction, DatabaseConfig config, string databaseTypeName)
            : base(dbInteraction, config, databaseTypeName, SQL_MAX_LENGTH)
        {

        }

        /// <summary>
        /// 最优化表,回收不使用的空间,并整理数据文件的碎片
        /// </summary>
        /// <param name="tableNames">表名列表,如果为null或空,则全部执行</param>
        protected override void PrimitiveOptimizeTable(List<string> tableNames)
        {
            const string sql = "VACUUM;";
            base.PrimitiveExecuteNonQuery(sql, DBVisitType.W, null);
        }

        /// <summary>
        /// 创建数据库对象
        /// </summary>
        /// <returns></returns>
        protected override IDatabase CreateDatabase()
        {
            return new SQLiteDatabase(this);
        }
    }
}
